package com.icexxx.ice_browser;

import java.util.HashMap;
import java.util.Map;

import cn.hutool.core.util.StrUtil;

public class DataContext {
    private static Map<String, String> map = new HashMap<String, String>();

    public static Map<String, String> getMap() {
        return map;
    }

    public static void setMap(Map<String, String> map) {
        DataContext.map = map;
    }

    public static String put(String key, String value) {
        if (key.equals("basePath") || key.equals("savePath")) {
            if (value.endsWith("/")) {
                value = StrUtil.removePrefix(value, "/");
            }
        }
        if (key.equals("savePath")) {
            if (value.contains("\\")) {
                value = value.replace("\\", "/");
            }
        }
        if (key.equals("basePath")) {
            if (!value.startsWith("http://")) {
                value = StrUtil.addPrefixIfNot(value, "http://");
            }
        }
        return map.put(key, value);
    }

    public static String get(String key) {
        return map.get(key);
    }
}
